﻿using System;
using System.Data;
using System.Data.OleDb;
using System.Collections;
using System.Data.SqlClient;

namespace iWMS.Common 
{
    /// <summary>
    /// Summary description for SQL.
    /// </summary>
    //*********************************************************************
    //
    // The SqlHelper class is intended to encapsulate high performance, scalable best practices for 
    // common uses of SqlClient.
    //
    //*********************************************************************
    public sealed class SQL
    {
        public SQL()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        //Return DataReader
        public static DataSet GetDataSet(string _Conn, string _Query)
        {
            DataSet ds = new DataSet();
            SqlCommand command = new SqlCommand(_Query);
            command.Connection = new SqlConnection(_Conn);
            SqlDataAdapter da = new SqlDataAdapter(command);

            command.Connection.Open();
            da.Fill(ds);
            command.Connection.Close();

            return ds;
        }

        public static bool ExecuteNonQuery(string _conn, string _query)
        {
            SqlConnection sqlConnection = new SqlConnection(_conn);
            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = _query;
            cmd.Connection = sqlConnection;

            try
            {
                sqlConnection.Open();
                cmd.ExecuteNonQuery();
                sqlConnection.Close();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

    }
}
